#ifndef __cplusplus
#include "stdlib.h"
#endif
#include "string.h"

#include "tolua++.h"

/* Exported function */
TOLUA_API int  tolua_luaMathEx_open (lua_State* tolua_S);

#include "./../luaMathExUI.h"
#include "./../luaInterpolation.h"

/* function to register type */
static void tolua_reg_types (lua_State* tolua_S)
{
}
 
/* function: math::norphs */
#ifndef TOLUA_DISABLE_tolua_luaMathEx_math_norphs00
static int tolua_luaMathEx_math_norphs00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
     !tolua_isnumber(tolua_S,1,0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,2,&tolua_err)
 )
  goto tolua_lerror;
 else
#endif
 {
  double phs = ((double)  tolua_tonumber(tolua_S,1,0));
  {
   double tolua_ret = (double)  math::norphs(phs);
   tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
  }
 }
 return 1;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'norphs'.",&tolua_err);
 return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE

/* function: math::interpolation */
#ifndef TOLUA_DISABLE_tolua_luaMathEx_math_interpolation00
static int tolua_luaMathEx_math_interpolation00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
     !tolua_isnumber(tolua_S,1,0,&tolua_err) ||
     !tolua_istable(tolua_S,2,0,&tolua_err) ||
     !tolua_istable(tolua_S,3,0,&tolua_err) ||
     !tolua_isnumber(tolua_S,4,0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,5,&tolua_err)
 )
  goto tolua_lerror;
 else
#endif
 {
  int n = ((int)  tolua_tonumber(tolua_S,1,0));
#ifdef __cplusplus
  double* arrx = Mtolua_new_dim(double, n);
#else
  double* arrx = (double*) malloc((n)*sizeof(double));
#endif
#ifdef __cplusplus
  double* arry = Mtolua_new_dim(double, n);
#else
  double* arry = (double*) malloc((n)*sizeof(double));
#endif
  double x = ((double)  tolua_tonumber(tolua_S,4,0));
  {
#ifndef TOLUA_RELEASE
   if (!tolua_isnumberarray(tolua_S,2,n,0,&tolua_err))
    goto tolua_lerror;
   else
#endif
   {
    int i;
    for(i=0; i<n;i++)
    arrx[i] = ((double)  tolua_tofieldnumber(tolua_S,2,i+1,0));
   }
  }
  {
#ifndef TOLUA_RELEASE
   if (!tolua_isnumberarray(tolua_S,3,n,0,&tolua_err))
    goto tolua_lerror;
   else
#endif
   {
    int i;
    for(i=0; i<n;i++)
    arry[i] = ((double)  tolua_tofieldnumber(tolua_S,3,i+1,0));
   }
  }
  {
   double tolua_ret = (double)  math::interpolation(n,arrx,arry,x);
   tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
  }
  {
   int i;
   for(i=0; i<n;i++)
    tolua_pushfieldnumber(tolua_S,2,i+1,(lua_Number) arrx[i]);
  }
  {
   int i;
   for(i=0; i<n;i++)
    tolua_pushfieldnumber(tolua_S,3,i+1,(lua_Number) arry[i]);
  }
#ifdef __cplusplus
  Mtolua_delete_dim(arrx);
#else
  free(arrx);
#endif
#ifdef __cplusplus
  Mtolua_delete_dim(arry);
#else
  free(arry);
#endif
 }
 return 1;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'interpolation'.",&tolua_err);
 return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE

/* function: math::array_max */
#ifndef TOLUA_DISABLE_tolua_luaMathEx_math_array_max00
static int tolua_luaMathEx_math_array_max00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
     !tolua_isnumber(tolua_S,1,0,&tolua_err) ||
     !tolua_istable(tolua_S,2,0,&tolua_err) ||
     !tolua_isnumber(tolua_S,3,0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,4,&tolua_err)
 )
  goto tolua_lerror;
 else
#endif
 {
  int n = ((int)  tolua_tonumber(tolua_S,1,0));
#ifdef __cplusplus
  double* arrx = Mtolua_new_dim(double, n);
#else
  double* arrx = (double*) malloc((n)*sizeof(double));
#endif
  int idx = ((int)  tolua_tonumber(tolua_S,3,0));
  {
#ifndef TOLUA_RELEASE
   if (!tolua_isnumberarray(tolua_S,2,n,0,&tolua_err))
    goto tolua_lerror;
   else
#endif
   {
    int i;
    for(i=0; i<n;i++)
    arrx[i] = ((double)  tolua_tofieldnumber(tolua_S,2,i+1,0));
   }
  }
  {
   double tolua_ret = (double)  math::array_max(n,arrx,idx);
   tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
   tolua_pushnumber(tolua_S,(lua_Number)idx);
  }
  {
   int i;
   for(i=0; i<n;i++)
    tolua_pushfieldnumber(tolua_S,2,i+1,(lua_Number) arrx[i]);
  }
#ifdef __cplusplus
  Mtolua_delete_dim(arrx);
#else
  free(arrx);
#endif
 }
 return 2;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'array_max'.",&tolua_err);
 return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE

/* function: math::array_min */
#ifndef TOLUA_DISABLE_tolua_luaMathEx_math_array_min00
static int tolua_luaMathEx_math_array_min00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
     !tolua_isnumber(tolua_S,1,0,&tolua_err) ||
     !tolua_istable(tolua_S,2,0,&tolua_err) ||
     !tolua_isnumber(tolua_S,3,0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,4,&tolua_err)
 )
  goto tolua_lerror;
 else
#endif
 {
  int n = ((int)  tolua_tonumber(tolua_S,1,0));
#ifdef __cplusplus
  double* arrx = Mtolua_new_dim(double, n);
#else
  double* arrx = (double*) malloc((n)*sizeof(double));
#endif
  int idx = ((int)  tolua_tonumber(tolua_S,3,0));
  {
#ifndef TOLUA_RELEASE
   if (!tolua_isnumberarray(tolua_S,2,n,0,&tolua_err))
    goto tolua_lerror;
   else
#endif
   {
    int i;
    for(i=0; i<n;i++)
    arrx[i] = ((double)  tolua_tofieldnumber(tolua_S,2,i+1,0));
   }
  }
  {
   double tolua_ret = (double)  math::array_min(n,arrx,idx);
   tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
   tolua_pushnumber(tolua_S,(lua_Number)idx);
  }
  {
   int i;
   for(i=0; i<n;i++)
    tolua_pushfieldnumber(tolua_S,2,i+1,(lua_Number) arrx[i]);
  }
#ifdef __cplusplus
  Mtolua_delete_dim(arrx);
#else
  free(arrx);
#endif
 }
 return 2;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'array_min'.",&tolua_err);
 return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE

/* function: math::array_max */
#ifndef TOLUA_DISABLE_tolua_luaMathEx_math_array_max01
static int tolua_luaMathEx_math_array_max01(lua_State* tolua_S)
{
 tolua_Error tolua_err;
 if (
     !tolua_isnumber(tolua_S,1,0,&tolua_err) ||
     !tolua_istable(tolua_S,2,0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,3,&tolua_err)
 )
  goto tolua_lerror;
 else
 {
  int n = ((int)  tolua_tonumber(tolua_S,1,0));
#ifdef __cplusplus
  double* arrx = Mtolua_new_dim(double, n);
#else
  double* arrx = (double*) malloc((n)*sizeof(double));
#endif
  {
#ifndef TOLUA_RELEASE
   if (!tolua_isnumberarray(tolua_S,2,n,0,&tolua_err))
    goto tolua_lerror;
   else
#endif
   {
    int i;
    for(i=0; i<n;i++)
    arrx[i] = ((double)  tolua_tofieldnumber(tolua_S,2,i+1,0));
   }
  }
  {
   double tolua_ret = (double)  math::array_max(n,arrx);
   tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
  }
  {
   int i;
   for(i=0; i<n;i++)
    tolua_pushfieldnumber(tolua_S,2,i+1,(lua_Number) arrx[i]);
  }
#ifdef __cplusplus
  Mtolua_delete_dim(arrx);
#else
  free(arrx);
#endif
 }
 return 1;
tolua_lerror:
 return tolua_luaMathEx_math_array_max00(tolua_S);
}
#endif //#ifndef TOLUA_DISABLE

/* function: math::array_min */
#ifndef TOLUA_DISABLE_tolua_luaMathEx_math_array_min01
static int tolua_luaMathEx_math_array_min01(lua_State* tolua_S)
{
 tolua_Error tolua_err;
 if (
     !tolua_isnumber(tolua_S,1,0,&tolua_err) ||
     !tolua_istable(tolua_S,2,0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,3,&tolua_err)
 )
  goto tolua_lerror;
 else
 {
  int n = ((int)  tolua_tonumber(tolua_S,1,0));
#ifdef __cplusplus
  double* arrx = Mtolua_new_dim(double, n);
#else
  double* arrx = (double*) malloc((n)*sizeof(double));
#endif
  {
#ifndef TOLUA_RELEASE
   if (!tolua_isnumberarray(tolua_S,2,n,0,&tolua_err))
    goto tolua_lerror;
   else
#endif
   {
    int i;
    for(i=0; i<n;i++)
    arrx[i] = ((double)  tolua_tofieldnumber(tolua_S,2,i+1,0));
   }
  }
  {
   double tolua_ret = (double)  math::array_min(n,arrx);
   tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
  }
  {
   int i;
   for(i=0; i<n;i++)
    tolua_pushfieldnumber(tolua_S,2,i+1,(lua_Number) arrx[i]);
  }
#ifdef __cplusplus
  Mtolua_delete_dim(arrx);
#else
  free(arrx);
#endif
 }
 return 1;
tolua_lerror:
 return tolua_luaMathEx_math_array_min00(tolua_S);
}
#endif //#ifndef TOLUA_DISABLE

/* Open function */
TOLUA_API int tolua_luaMathEx_open (lua_State* tolua_S)
{
 tolua_open(tolua_S);
 tolua_reg_types(tolua_S);
 tolua_module(tolua_S,NULL,0);
 tolua_beginmodule(tolua_S,NULL);
  tolua_module(tolua_S,"math",0);
  tolua_beginmodule(tolua_S,"math");
   tolua_function(tolua_S,"norphs",tolua_luaMathEx_math_norphs00);
   tolua_function(tolua_S,"interpolation",tolua_luaMathEx_math_interpolation00);
   tolua_function(tolua_S,"array_max",tolua_luaMathEx_math_array_max00);
   tolua_function(tolua_S,"array_min",tolua_luaMathEx_math_array_min00);
   tolua_function(tolua_S,"array_max",tolua_luaMathEx_math_array_max01);
   tolua_function(tolua_S,"array_min",tolua_luaMathEx_math_array_min01);
  tolua_endmodule(tolua_S);
 tolua_endmodule(tolua_S);
 return 1;
}


#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
 TOLUA_API int luaopen_luaMathEx (lua_State* tolua_S) {
 return tolua_luaMathEx_open(tolua_S);
};
#endif

